/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.edu.kamai.client.download;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.net.URL;

/**
 *
 * @author xyzhu
 */
public class fileDownload extends Thread{

    public fileDownload(String url,String fn){
        fileUrl = url;
        localFileName = fn;
    }
    
    @Override
    public void run() {
        try{
            BufferedInputStream in = new BufferedInputStream(
                    new URL(fileUrl).openStream());
            
            FileOutputStream fos = new FileOutputStream(localFileName);
            
            BufferedOutputStream bout = new BufferedOutputStream(fos,1024);
            byte[] data = new byte[1024];
            int x=0;
            while((x=in.read(data,0,1024))>=0){
                bout.write(data,0,x);
            }
            bout.close();
            in.close();
        }catch(Exception ex){
            ex.printStackTrace();
        }
    }
    
    public static void main(String[] args){
                   //"http://localhost:8080/kamai_edu/UpLoad";
        String url = "http://localhost:8080/kamai_edu/UpLoad/Paper/8f7ea7895eb094519dee27e518057296.xml";
        
        String fn = "test_xzhu_download.xml";
        fileDownload fd = new fileDownload(url, fn);
        fd.start();
    }
    
    private String fileUrl;
    private String localFileName;
}
